package com.hulk.ratel.notify.initializer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @author 作者 hulk
 * @version 创建时间：2016年7月6日 下午4:50:19 类说明
 */



@Configuration
//@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurationSupport {


	@Autowired
	private GlobalProperties globalProperties;


	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		//过滤swagger
		if (globalProperties.getSwaggerOpen()) {
			registry.addResourceHandler("swagger-ui.html")
					.addResourceLocations("classpath:/META-INF/resources/");

			registry.addResourceHandler("/webjars/**")
					.addResourceLocations("classpath:/META-INF/resources/webjars/");

			registry.addResourceHandler("/swagger-resources/**")
					.addResourceLocations("classpath:/META-INF/resources/swagger-resources/");

			registry.addResourceHandler("/swagger/**")
					.addResourceLocations("classpath:/META-INF/resources/swagger*");

			registry.addResourceHandler("/v2/api-docs/**")
					.addResourceLocations("classpath:/META-INF/resources/v2/api-docs/");
		}

	}

	@Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //配置跳转
       // registry.addViewController("/nav").setViewName("forward:/static/nav.html");
    }


	@Override
	public void configurePathMatch(PathMatchConfigurer configurer) {
		configurer.setUseSuffixPatternMatch(false);
	}

	@Bean
	public SpringContextHolder SpringContextHolder() {
		return new SpringContextHolder();
	}

	@Bean
	public LimitInterceptor rateLimitInterceptor(){
		return new LimitInterceptor();
	}


	@Override
	public void addInterceptors(InterceptorRegistry registry ) {

		registry.addInterceptor(rateLimitInterceptor()).addPathPatterns("/**").excludePathPatterns("/rest/heartbeat").excludePathPatterns("/favicon.ico");

	}


}
